<template>
	<a-card :bordered="false" class="mt-2">
		<s-table
			ref="tableRef"
			:columns="columns"
			:data="loadData"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
		>
			<template #operator>
				<a-space>
					<a-button type="primary" @click="upload.openUpload()">
						<template #icon>
							<import-outlined />
						</template>
						导入
					</a-button>
				</a-space>
			</template>
		</s-table>
	</a-card>
	<Form ref="formRef" @successful="tableRef.refresh(true)" />
	<Upload ref="upload" @successful="tableRef.refresh(true)" />
</template>

<script setup name="Company">
	import Form from '@/views/tjzy/phone/filter/form.vue'
	import Upload from '@/views/tjzy/excel/imports/upload.vue'
	import excelImportApi from '@/api/tjzy/excel/imports/excelImportApi'

	const upload = ref()
	const searchFormState = ref({
		projectCode: undefined,
		phoneNumber: undefined,
		name: undefined,
		idCard: undefined
	})
	const searchFormRef = ref()
	const tableRef = ref()
	const formRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
	const columns = [
		{
			title: '类型',
			dataIndex: 'type'
		},
		{
			title: '总数',
			dataIndex: 'totalCount'
		},
		{
			title: '已完成数量',
			dataIndex: 'completedCount'
		},
		{
			title: '异常数量',
			dataIndex: 'errorCount'
		},
		{
			title: '创建人',
			dataIndex: 'createUserName'
		},
		{
			title: '创建时间',
			dataIndex: 'createTime',
			ellipsis: true
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center'
		}
	]

	const loadData = (parameter) => {
		searchFormState.value.current = parameter.current
		searchFormState.value.size = parameter.size
		return excelImportApi.pageList(searchFormState.value).then((res) => {
			return res
		})
	}
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
</script>
